package x.zero.controller.sys;



import x.zero.pojo.entity.SysEmailConfig;
import x.zero.pojo.vo.admin.EmailVo;
import x.zero.service.sys.SysEmailConfigService;
import x.zero.util.CommonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/sys/sysEmailConfig")
public class SysEmailConfigController {

    @Autowired
    private SysEmailConfigService emailService;


    @GetMapping(value = "/{id}")
    public Object get(Long id) {
        return CommonResult.success(emailService.queryById(id));
    }


    @PostMapping(value = "/update")
    @ApiOperation("配置邮件")
    public Object emailConfig(@Validated @RequestBody SysEmailConfig emailConfig) {
        emailService.updateById(emailConfig);
        return CommonResult.success();
    }


    @PostMapping(value = "/send")
    @ApiOperation("发送邮件")
    public Object send(@Validated @RequestBody EmailVo emailVo) throws Exception {
        emailService.send(emailVo, emailService.queryById(1));
        return CommonResult.success();
    }
}

